package com.wd.lookcar.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.widget.AppCompatRadioButton
import androidx.recyclerview.widget.RecyclerView
import com.wd.common.bean.AllQuickSearchBean
import com.wd.common.DataHelper
import com.wd.lookcar.R
import com.wd.lookcar.myview.FlowRadioGroup

/**
 * Created by Android Studio.
 * author: 张文龙
 * Date:
 * Time: 2023/9/13 20:30
 * 备注：
 */
class ConditionAdapter(
    private var context: Context,
    private var list: ArrayList<AllQuickSearchBean.Result.ScreeningCondition>,
) : RecyclerView.Adapter<ConditionAdapter.Holder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
        val view = LayoutInflater.from(context).inflate(R.layout.squre_item, parent, false)
        return Holder(view)
    }

    override fun getItemCount() = list.size

    override fun onBindViewHolder(holder: Holder, position: Int) {
        val screeningCondition = list[position]
        holder.text.text = screeningCondition.conditionName
        for(index in 0 until screeningCondition.conditionPropertyList.size){
            val radio = AppCompatRadioButton(context).apply {
                text = screeningCondition.conditionPropertyList[index]!!.configName
                buttonDrawable = null
                background = resources.getDrawable(R.drawable.top_button_check)
            }
            radio.setOnClickListener {
                DataHelper.map[screeningCondition.parameterName!!] =
                    screeningCondition.conditionPropertyList[index]!!.configValue!!
            }
            holder.rg.addView(radio)
        }
    }

    class Holder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var text: TextView
        var rg : FlowRadioGroup
        init {
            text = itemView.findViewById(R.id.conditionname)
            rg = itemView.findViewById(R.id.cond_rec)
        }
    }
}